package com.ruoyi.system.controller;

import cn.hutool.core.map.MapUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.MessageStatusEnum;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author 孙先生
 * @version 1.0
 * @date 2022/12/12 15:22
 */
@RestController
@RequestMapping("/system/dashboard")
public class IndexController {
    @Autowired
    private ILendRecordService lendRecordService;

    @Autowired
    private IStudentService studentService;

    @Autowired
    private IMessageService messageService;
    @Autowired
    private IBookService bookService;
    @Autowired
    private ICategoryService categoryService;


    @GetMapping
    public AjaxResult index(){
        return AjaxResult.success(
                MapUtil.builder()
                        .put("peopleCount",studentService.selectStudentList(new Student()).size())
                        .put("username", SecurityUtils.getLoginUser().getUser().getNickName())
                        .put("messageCount",categoryService.selectCategoryList(new Category()).size())
                        .put("bookCount",bookService.selectBookList(new Book()).size())
                        .put("todayLendCount",lendRecordService.selectLendRecordList(new LendRecord().setLendTime(new Date())).size())
                        .build()
        );
    }
}
